const ejs = require('ejs')
//使用类似于jsp的语法
//<% %> 语句
//<%= %> 输出
//<%- %> 输出，但不转义
//<%# %> 注释

let str = 'hello <%= name %>'

let res = ejs.render(str, {name: 'world'})
console.log(res);

//使用模板文件
let list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let result = ejs.render(
`<ul> <% list.forEach(item => { %>
    <li><%= item %></li>
    <% }) %>
</ul>`
, {list: list}, (err, data) => {
    console.log(data);
}
)
console.log(result);


const fs = require('fs')
const html = fs.readFileSync('./index.html', 'utf-8').toString()
const rst = ejs.render(html, {list: list}, (err, data) => {
    console.log(data);
}
)
console.log(rst);